M6f: ordered stages on root/sort tuple steps (joins/index 6 & 12)#23
Merged
Conversation
mark_binding's # branch now moves a preceding filter into an ordered .stages list before pushing the index stage (jsonata move-on-#), so an index numbers the post-filter/post-sort survivors. The evaluator's apply_stages runs the stages in order in eval_path_tuple's seeding and main loop, and the sort branch binds its #-index. Gated on .stages/sort-.index — non-tuple paths and existing joins are untouched. Defers library-joins 7,8,10 (flat-stages cross-product rework). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…egressions Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adversarial review found $#$a^($)#$b[$b<2] returned [1,1] vs jsonata undefined: jsonata's evaluateTupleStep binds a sort step's index ONLY when sorting a non-tuple-bound stream (the `tupleBindings === undefined` branch). Gate the sort-index binding on the incoming tuples carrying no key beyond "@"; index/6 ($^($)#$pos, a raw stream) still binds, the double-index case now yields undefined. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports JSONata v2.2.1's ordered
stagesmodel for path steps so a#$vindex that follows a filter or sort renumbers the post-filter/post-sort survivors — closing the two cleanly-fixable remaining joins cases.cbb48f9):mark_binding's#branch now applies jsonata's move-on-#rule — a filter preceding the#moves into an ordered.stageslist ({filter}/{index}), then the index is pushed as a stage; the@-focus S0215 guard also rejects pre-existing stages.cbb48f9): newapply_stages(filter → predicate; index → renumber tuples 0-based), applied ineval_path_tuple's seeding and main loop; the sort branch binds its#-index. All gated on.stages/sort-.index, so non-tupleeval_pathand the existing M6c–M6e joins are untouched.51a32ca): regen, additions-only.0183939): adversarial review caught$#$a^($)#$b[$b<2]→[1,1]vs jsonataundefined(a contrived double-index around a sort). Fixed to jsonata's exact rule: a sort binds its index only on a raw, not-yet-tuple-bound stream.Results
joins/index/6,/12).%-parent / M6c–M6e joins unchanged).Deferred (the last 3 joins cases)
library-joins/7,8,10(books@$b[…][1],…#$ib2,…[1][]) require stages applied to the whole post-cross-product stream, but our parser nests predicated tuple-steps into sub-paths evaluated per outer tuple (so a positional[1]applies per-loan, not globally). Faithfully closing them means jsonata's flat-steps + global-stages rework — flattening predicated tuple steps, which touches the machinery M6b (keepArray nesting) and M6c–M6e (all joins) rely on. Deferred as a separate, higher-risk architectural item.Test plan
busted spec/— 498/0busted spec/jsonata_suite_spec.lua— zero-regression guard greenbash scripts/run-suite.sh— 1251/1682, joins 40/43🤖 Generated with Claude Code